package com.yuan.statemachine.business;

import com.yuan.statemachine.core.AbstractStateMachine;
import com.yuan.statemachine.core.StateResponseBody;

/**
 * @author wjwei
 */
public abstract class BusinessStateMachine<F extends Enum<F>,S extends Enum<S>,E extends Enum<E>> extends AbstractStateMachine<F,S,E> {

    public MessageBody created(Object data) {
        return MessageBody.stateDefault(BusinessStateCode.CREATED_ERROR);
    }

    public MessageBody pay(Object data) {
        return MessageBody.stateDefault(BusinessStateCode.PAY_ERROR);
    }

    public MessageBody intercept(Object data) {
        return MessageBody.stateDefault(BusinessStateCode.INTERCEPT_ERROR);
    }

    public MessageBody collect(Object data) {
        return MessageBody.stateDefault(BusinessStateCode.COLLECT_ERROR);
    }

    public MessageBody deliver(Object data) {
        return MessageBody.stateDefault(BusinessStateCode.DELIVER_ERROR);
    }

    public MessageBody invalid(Object data) {
        return MessageBody.stateDefault(BusinessStateCode.INVALID_ERROR);
    }

    public MessageBody noEvent() {
        return MessageBody.stateDefault(BusinessStateCode.NO_EVENT);
    }


    @Override
    public StateResponseBody doEvent(Enum<E> eventEnum, Object data) {
        BusinessEventEnum event = (BusinessEventEnum) eventEnum;
        switch (event) {
            case CREATED:
                return this.created(data);
            case PAY:
                return this.pay(data);
            case INTERCEPT:
                return this.intercept(data);
            case COLLECT:
                return this.collect(data);
            case DELIVER:
                return this.deliver(data);
            case INVALID:
                return this.invalid(data);
            default:
                return this.noEvent();
        }
    }

}
